package cn.cvs.service.storageRecord;

import cn.cvs.dao.storageRecord.StorageRecordMapper;
import cn.cvs.pojo.StorageRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class StorageRecordServiceImpl implements StorageRecordService {
    @Autowired
    private StorageRecordMapper storageRecordMapper;
    @Override
    public int add(StorageRecord storageRecord) {
//        return storageRecordMapper.add(storageRecord);
        int result=0;
        try {
            if (storageRecordMapper.add(storageRecord)==1){
                result=1;
                //测试事务回滚时，打开注释
                //throw new RuntimeException();
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    @Override
    public int del(int id) {
        int result=0;
        try {
            if (storageRecordMapper.del(id)==1){
                result=1;
                //测试事务回滚时，打开注释
                //throw new RuntimeException();
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    @Override
    public int modify(StorageRecord storageRecord) {
        int result=0;
        try {
            if (storageRecordMapper.modify(storageRecord)==1){
                result=1;
                //测试事务回滚时，打开注释
                //throw new RuntimeException();
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }
}
